BitmapText Class
A Text Object will create (a) line(s) of text using bitmap font. To split a line you can use "\n", "\r" or "\r\n" You can generate the fnt files using bmfont for windows or bmglyph for mac.
Constructor
BitmapText
-
text -
font -
[style]
Parameters:
-
textStringThe copy that you would like the text to display
-
fontObjectThe font data object (this is generally grabbed from
game.cache.getBitmapFont('mykey'));-
nameStringThe name of the font
-
sizeNumberThe base size of the font
-
lineHeightNumberThe line height of the font
-
charsObjectThe characters in the font, each should have a texture and kerning info
-
-
[style]Object optionalThe style parameters
-
[size=null]Number optionalThe font size of the text, overrides the font's size
-
[align="left"]String optionalAn alignment of the multiline text ("left", "center" or "right")
-
Item Index
Methods
Properties
Methods
addChildAt
-
child -
index
Adds a child to the object at a specified index. If the index is out of bounds an error will be thrown
clone
()
Clones this BitmapText to get another just like it
Returns:
BitmapText
destroy
()
Destroys this object.
destroyAllChildren
()
Container
chainable
Destroys all the children of the object.
Returns:
Returns itself.
disablePhysics
-
callback
Disbales physics for this sprite
Parameters:
-
callbackFunctionThe callback function to call after physics have been disabled
Returns:
Returns itself.
emit
-
type -
data
Emits an event which will run all registered listeners for the event type
Parameters:
-
typeStringThe event name to emit
-
dataMixedAny data you want passed along with the event
Returns:
Returns itself.
enablePhysics
-
system -
callback
Enables physics for this sprite
Parameters:
-
systemPhysicsSystemThe system for the sprite to be in
-
callbackFunctionThe callback function to call after physics have been enabled
Returns:
Returns itself.
hide
()
Container
chainable
Sets the container to visible = false
Returns:
Returns itself.
off
-
type -
listener
Removes a listener function for an event type
Parameters:
-
typeStringThe event name to emit
-
listenerFunctionThe function to remove
Returns:
Returns itself.
on
-
type -
listener
Registers a listener function to be run on an event occurance
Parameters:
-
typeStringThe event name to listen for
-
listenerFunctionThe function to execute when the event happens
Returns:
Returns itself.
once
-
type -
listener
Registers a one-time callback for an event
Parameters:
-
typeStringThe event name to listen for
-
listenerFunctionthe callback to call when the event occurs
Returns:
Returns itself.
onCollide
-
obj -
collision
Called whenever a collision occurs
Parameters:
Returns:
If you return false explicitly the engine will not
solve the collision. In this way you can make thing "not collide" if
you don't want their types to collide.
parseXML
-
key -
xml -
texture
Parses an XML font file into a font object that can be passed into a BitmapText instance. This is called by the Cache when XML bitmap data is added.
Parameters:
-
keyStringThe cache key for the font
-
xmlDocumentThe XML document to parse
-
textureTextureThe texture to use for creating character textures
removeAllChildren
()
Container
chainable
Removes all children from the object.
Returns:
Returns itself.
renderText
()
Renders the text character sprites when the text is dirty. This is automatically called when the text/style becomes dirty.
setMass
-
mass
Sets the mass of this sprite
Parameters:
-
massNumberThe new mass of the object
Returns:
Returns itself.
setPosition
-
x -
y
Sets the position of this sprite
Parameters:
-
xNumber | VectorThe x coord to set position to, if a Vector is passed the y param is ignored
-
yNumberThe y coord to set position to
Returns:
Returns itself.
setRotation
-
rotation
Sets the rotation of this sprite
Parameters:
-
rotationNumberThe new rotation of the object in radians
Returns:
Returns itself.
setStyle
-
style
Sets the style of the text based on a style object.
Parameters:
-
styleObjectThe style object
-
alignStringThe alignment of the text, can be 'left', 'center', or 'right'
-
sizeNumberThe font size of the text to display
-
setVelocity
-
x -
y
Sets the velocity of this sprite
Parameters:
-
xNumber | VectorThe x coord to set the velocity to, if a Vector is passed the y param is ignored
-
yNumberThe y coord to set the velocity to
Returns:
Returns itself.
show
()
Container
chainable
Sets the container to visible = true
Returns:
Returns itself.
updateTransform
()
private
Updates the text when dirty, called each frame by PIXI's render methods
Properties
_phys
Object
private
The physics namespace that all physics properties go into. Those properties are:
- system {PhysicsSystem} PhysicsSystem that this object is a part of.
- active {Boolean} Whether or not this target is actively having physics simulated.
Default: {}
_text
String
private
The actual text that is currently rendered, please use the text property
and do not set this directly.
_velocity
Vector
private
The internal velocity value, used as a reusable vector for the setVelocity function. Setting this directly has no effect.
alpha
Number
The opacity of the object.
children
Array
[read-only] The of children of this object.
dirty
Boolean
Whether or not the bitmap text is dirty and should be redrawn
Default: false
font
Object
The font descriptor that holds the font data (name, size, chars, etc)
hitArea
Rectangle | Polygon | Circle | Ellipse
This is the defined area that will pick up mouse / touch events. It is null by default. Setting it is a neat way of optimising the hitTest function that the interactionManager will use (as it will not need to hit test all the children)
inertia
Number
The moment of inertia of this object, only set this before enabling physics (has no effect after enabling)
Default: 0
interactive
Boolean
Wether or not the object will handle mouse events
Default: false
mass
Number
The mass of this object, please use setMass to set this value
Default: 0
monospace
Number
A monospacing to apply to the font instead of the actual character/kerning spacing.
When set to 0 the default font values will be used.
Default: 0
parent
DisplayObject
[read-only] The display object that contains this display object.
position
Point
The coordinate of the object relative to the local coordinates of the parent.
rotation
Number
The rotation of the object in radians.
scale
Point
The scale factor of the object.
stage
Stage
[read-only] The stage the display object is connected to, or undefined if it is not connected to the stage.
text
String
The text that will be rendered.
visible
Boolean
The visibility of the object.
Events
click
A callback that is used when the users clicks on the displayObject with their mouse
Event Payload:
-
interactionDataInteractionData
collision
On Collision Event called when this sprite collides into another, or is being collided into by another. By default if something collides with a collectable sprite we destroy the collectable and if we collide with a solid tile we kill our velocity. This method will emit a 'collision' event that you can listen for
mousedown
A callback that is used when the user clicks the mouse down over the displayObject
Event Payload:
-
interactionDataInteractionData
mousemove
A callback that is used when the user moves the mouse while over the displayObject
Event Payload:
-
interactionDataInteractionData
mouseout
A callback that is used when the users mouse leaves the displayObject
Event Payload:
-
interactionDataInteractionData
mouseover
A callback that is used when the users mouse rolls over the displayObject
Event Payload:
-
interactionDataInteractionData
mouseup
A callback that is used when the user releases the mouse that was over the displayObject for this callback to be fired the mouse must have been pressed down over the displayObject
Event Payload:
-
interactionDataInteractionData
mouseupoutside
A callback that is used when the user releases the mouse that was over the displayObject but is no longer over the displayObject for this callback to be fired, The touch must have started over the displayObject
Event Payload:
-
interactionDataInteractionData
separate
On Seperate Event called when this sprite collides into another, or is being collided into by another. By default if something collides with a collectable sprite we destroy the collectable and if we collide with a solid tile we kill our velocity. This method will emit a 'collision' event that you can listen for
Event Payload:
-
objSpriteColliding sprite
-
colShapecp.ShapeThe colliding physics shape
-
myShapecp.ShapeYour physics shape that caused the collision
tap
A callback that is used when the users taps on the displayObject with their finger basically a touch version of click
Event Payload:
-
interactionDataInteractionData
touchend
A callback that is used when the user releases a touch over the displayObject
Event Payload:
-
interactionDataInteractionData
touchendoutside
A callback that is used when the user releases the touch that was over the displayObject for this callback to be fired, The touch must have started over the displayObject
Event Payload:
-
interactionDataInteractionData
touchstart
A callback that is used when the user touch's over the displayObject
Event Payload:
-
interactionDataInteractionData